from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-12 14:04:21.749101
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 12, Dec, 2021
Time: 14:04:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4602
Nobs: 503.000 HQIC: -47.9191
Log likelihood: 5792.63 FPE: 1.14911e-21
AIC: -48.2153 Det(Omega_mle): 9.62534e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.368672 0.079897 4.614 0.000
L1.Burgenland 0.096687 0.044158 2.190 0.029
L1.Kärnten -0.116199 0.022666 -5.127 0.000
L1.Niederösterreich 0.174158 0.091321 1.907 0.057
L1.Oberösterreich 0.130903 0.092523 1.415 0.157
L1.Salzburg 0.281200 0.047352 5.939 0.000
L1.Steiermark 0.019427 0.061174 0.318 0.751
L1.Tirol 0.108571 0.049380 2.199 0.028
L1.Vorarlberg -0.084855 0.043533 -1.949 0.051
L1.Wien 0.027919 0.083074 0.336 0.737
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.019222 0.177027 0.109 0.914
L1.Burgenland -0.051922 0.097839 -0.531 0.596
L1.Kärnten 0.036051 0.050221 0.718 0.473
L1.Niederösterreich -0.214628 0.202337 -1.061 0.289
L1.Oberösterreich 0.472345 0.205001 2.304 0.021
L1.Salzburg 0.312217 0.104917 2.976 0.003
L1.Steiermark 0.102563 0.135542 0.757 0.449
L1.Tirol 0.310915 0.109410 2.842 0.004
L1.Vorarlberg 0.008263 0.096455 0.086 0.932
L1.Wien 0.015509 0.184066 0.084 0.933
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222540 0.040735 5.463 0.000
L1.Burgenland 0.090509 0.022513 4.020 0.000
L1.Kärnten -0.004979 0.011556 -0.431 0.667
L1.Niederösterreich 0.222453 0.046559 4.778 0.000
L1.Oberösterreich 0.168513 0.047172 3.572 0.000
L1.Salzburg 0.036424 0.024142 1.509 0.131
L1.Steiermark 0.026874 0.031189 0.862 0.389
L1.Tirol 0.076571 0.025176 3.041 0.002
L1.Vorarlberg 0.055676 0.022195 2.508 0.012
L1.Wien 0.106845 0.042355 2.523 0.012
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159287 0.039781 4.004 0.000
L1.Burgenland 0.042684 0.021986 1.941 0.052
L1.Kärnten -0.012643 0.011285 -1.120 0.263
L1.Niederösterreich 0.152127 0.045468 3.346 0.001
L1.Oberösterreich 0.344976 0.046067 7.489 0.000
L1.Salzburg 0.100406 0.023576 4.259 0.000
L1.Steiermark 0.109513 0.030459 3.595 0.000
L1.Tirol 0.087185 0.024586 3.546 0.000
L1.Vorarlberg 0.053597 0.021675 2.473 0.013
L1.Wien -0.037717 0.041362 -0.912 0.362
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161364 0.076387 2.112 0.035
L1.Burgenland -0.042334 0.042217 -1.003 0.316
L1.Kärnten -0.036772 0.021670 -1.697 0.090
L1.Niederösterreich 0.128169 0.087308 1.468 0.142
L1.Oberösterreich 0.186660 0.088458 2.110 0.035
L1.Salzburg 0.255674 0.045271 5.648 0.000
L1.Steiermark 0.074774 0.058486 1.278 0.201
L1.Tirol 0.131820 0.047210 2.792 0.005
L1.Vorarlberg 0.104122 0.041620 2.502 0.012
L1.Wien 0.039825 0.079424 0.501 0.616
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.083414 0.060468 1.379 0.168
L1.Burgenland 0.015045 0.033420 0.450 0.653
L1.Kärnten 0.051000 0.017154 2.973 0.003
L1.Niederösterreich 0.178124 0.069114 2.577 0.010
L1.Oberösterreich 0.338516 0.070024 4.834 0.000
L1.Salzburg 0.049357 0.035837 1.377 0.168
L1.Steiermark -0.006031 0.046298 -0.130 0.896
L1.Tirol 0.125023 0.037372 3.345 0.001
L1.Vorarlberg 0.058662 0.032947 1.781 0.075
L1.Wien 0.108608 0.062873 1.727 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171067 0.073308 2.334 0.020
L1.Burgenland 0.010837 0.040516 0.267 0.789
L1.Kärnten -0.060813 0.020797 -2.924 0.003
L1.Niederösterreich -0.113907 0.083790 -1.359 0.174
L1.Oberösterreich 0.234311 0.084893 2.760 0.006
L1.Salzburg 0.038362 0.043447 0.883 0.377
L1.Steiermark 0.263153 0.056129 4.688 0.000
L1.Tirol 0.488906 0.045308 10.791 0.000
L1.Vorarlberg 0.070938 0.039943 1.776 0.076
L1.Wien -0.099901 0.076223 -1.311 0.190
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.141354 0.081048 1.744 0.081
L1.Burgenland -0.012772 0.044794 -0.285 0.776
L1.Kärnten 0.063683 0.022993 2.770 0.006
L1.Niederösterreich 0.171347 0.092636 1.850 0.064
L1.Oberösterreich -0.075662 0.093856 -0.806 0.420
L1.Salzburg 0.221745 0.048034 4.616 0.000
L1.Steiermark 0.134974 0.062055 2.175 0.030
L1.Tirol 0.051675 0.050091 1.032 0.302
L1.Vorarlberg 0.142016 0.044160 3.216 0.001
L1.Wien 0.165416 0.084271 1.963 0.050
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458291 0.044985 10.188 0.000
L1.Burgenland -0.001481 0.024862 -0.060 0.953
L1.Kärnten -0.013784 0.012762 -1.080 0.280
L1.Niederösterreich 0.178271 0.051416 3.467 0.001
L1.Oberösterreich 0.263484 0.052093 5.058 0.000
L1.Salzburg 0.018974 0.026661 0.712 0.477
L1.Steiermark -0.011458 0.034443 -0.333 0.739
L1.Tirol 0.071540 0.027802 2.573 0.010
L1.Vorarlberg 0.056019 0.024510 2.286 0.022
L1.Wien -0.018162 0.046773 -0.388 0.698
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.027908 0.093823 0.157465 0.138746 0.065885 0.081011 0.016331 0.208995
Kärnten 0.027908 1.000000 -0.034953 0.130589 0.049777 0.073993 0.455807 -0.081302 0.097125
Niederösterreich 0.093823 -0.034953 1.000000 0.280601 0.100952 0.254308 0.050299 0.142373 0.248675
Oberösterreich 0.157465 0.130589 0.280601 1.000000 0.196299 0.285769 0.160557 0.124852 0.186691
Salzburg 0.138746 0.049777 0.100952 0.196299 1.000000 0.120952 0.060719 0.109897 0.068973
Steiermark 0.065885 0.073993 0.254308 0.285769 0.120952 1.000000 0.131765 0.088610 0.008304
Tirol 0.081011 0.455807 0.050299 0.160557 0.060719 0.131765 1.000000 0.063227 0.126869
Vorarlberg 0.016331 -0.081302 0.142373 0.124852 0.109897 0.088610 0.063227 1.000000 -0.009920
Wien 0.208995 0.097125 0.248675 0.186691 0.068973 0.008304 0.126869 -0.009920 1.000000